import datetime,os
import time


def GUI():
    print('-' * 102)
    print('|{: <100}|'.format(''))
    print('*{:^100}*'.format('AliyunDomainRecord'))
    print('|{: <100}|'.format(''))
    print('*{:^20}{:^20}{:^20}{:^20}{:^20}*'.format(
        '(0)' + 'exit', '(1)' + 'ListRecord', '(2)' + 'AddRecord', '(3)' + 'DeleteRecord', '(4)' + "ModifyRecord")
    )
    print('|{: <100}|'.format(''))
    print('*{:^100}*'.format('(5)DomainInfo'))
    print('|{: <100}|'.format(''))
    print('-' * 102)

def RecordList(Records:list):
    list = ['index','Status','RR','Locked','Type','Value',"UpdateTimestamp",'CreateTimestamp']
    print('+{:-^5}+{:-^10}+{:-^10}+{:-^10}+{:-^15}+{:-^15}+{:-^22}+{:-^22}+'.format('','','','','','','',''))
    print('|{:-^5}|{:^10}|{:^10}|{:^10}|{:^15}|{:^15}|{:^22}|{:^22}|'.format(
        list[0],list[1], list[2], list[3], list[4],list[5],list[6],list[7])
    )
    print('+{:-^5}+{:-^10}+{:-^10}+{:-^10}+{:-^15}+{:-^15}+{:-^22}+{:-^22}+'.format('', '', '', '', '', '', '',''))
    for index,item in enumerate(Records):
        index += 1
        update_str = str(item.update_timestamp)
        update_int = int(update_str[:-3])
        create_str = str(item.create_timestamp)
        create_int = int(create_str[:-3])
        update = datetime.datetime.fromtimestamp(update_int).strftime('%Y-%m-%d %H:%M:%S')
        create = datetime.datetime.fromtimestamp(create_int).strftime('%Y-%m-%d %H:%M:%S')
        print('|{:^5} {:^10} {:^10} {:^10} {:^15} {:^15} {:^22} {:^22}|'.format(
            index,item.status, item.rr, item.locked, item.type, item.value,update,create))
        print('+{:-^5}+{:-^10}+{:-^10}+{:-^10}+{:-^15}+{:-^15}+{:-^22}+{:-^22}+'.format('','','','','','','',''))

def AddRecords():
    while True:
        # 清除前面的输出
        os.system('cls' if os.name == 'nt' else 'clear')
        RecordName = input('Please input your RecordName:')
        try:
            IP = input('Please input your Record IP:')
            print(f'\nYour RecordName is {RecordName} \nYour RecordRecordNameP is {IP}\n')
            select = input('Enter YES to confirm,\n' +
                           'Enter NO to select again,\n' +
                           'Other keys exit:').lower()
        except:
            print('Please check your input......')
            time.sleep(3)
        if(select == 'yes'):
            return [RecordName,IP]
        elif(select == 'no'):
            continue
        else:
            break

def DomainInfo(info):
    print('+'+'-' * 40+'+')
    print('|{: <40}|'.format('   AliDomain: '+str(info.ali_domain)))
    print('|{: <40}|'.format('  DndServers: '))
    for item in info.dns_servers.dns_server:
        print('|{: <40}|'.format('        '+item))
    print('|{: <40}|'.format('  VersionName: '+str(info.version_name)))
    print('|{: <40}|'.format('   DomainName: '+str(info.domain_name)))
    print('|{: <40}|'.format('   CreateTime: '+str(info.create_time)))
    print('|{: <40}|'.format('     PunyCode: '+str(info.puny_code)))
    print('|{: <40}|'.format('  VersionCode: '+str(info.version_code)))
    print('+'+'-' * 40+'+')





